package com.example.administrator.wallet.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.example.administrator.wallet.R;
import com.example.administrator.wallet.model.bean.MainBean;

import java.util.List;

/**
 * Effect:
 * <p>
 * Author:  CaiYapeng
 * <p>
 * Time  :  2018/7/10.
 */
//当前委托  item_current_delegate     CurrentDelegateFragment   CurrentDelegateBean
public class CurrentDelegateAdapter extends BaseAdapter {
    private Context context;
    private List<MainBean.DataBean.ListBean> datas;
    private OnClick click;

    public CurrentDelegateAdapter(Context activity, List<MainBean.DataBean.ListBean> dataBeanList) {
        this.context = activity;
        this.datas = dataBeanList;
    }

    @Override
    public int getCount() {
        return datas == null ? 0 : datas.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = View.inflate(context, R.layout.item_current_delegate, null);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.tv_sign = (TextView) view.findViewById(R.id.tv_sign); //买卖标志
        holder.tv_Currency_transaction = (TextView) view.findViewById(R.id.tv_Currency_transaction);//买卖币种
        holder.tv_number_Completed = (TextView) view.findViewById(R.id.tv_number_Completed);//已交易购买的数量
        holder.tv_number_all = (TextView) view.findViewById(R.id.tv_number_all);//应交易的总数量
        holder.tv_price = (TextView) view.findViewById(R.id.tv_price);//价格
        holder.tv_total = (TextView) view.findViewById(R.id.tv_total);//总价
        holder.bt_Delegate_status = (Button) view.findViewById(R.id.bt_Delegate_status);//撤销
        holder.tv_data = (TextView) view.findViewById(R.id.tv_data);//日期


        holder.tv_sign.setText(datas.get(i).getCoin_symbol());
//        Glide.with(context).load(datas.get(i).getIcon()).into(holder.iv_sign);
        holder.tv_Currency_transaction.setText(datas.get(i).getBalance());
        holder.tv_number_Completed.setText("≈￥" + datas.get(i).getMoney());
        holder.tv_number_all.setText("≈￥" + datas.get(i).getMoney());
        holder.tv_price.setText("≈￥" + datas.get(i).getMoney());
        holder.tv_total.setText("≈￥" + datas.get(i).getMoney());
        holder.bt_Delegate_status.setText("≈￥" + datas.get(i).getMoney());
        holder.tv_data.setText("≈￥" + datas.get(i).getMoney());

        holder.bt_Delegate_status.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CurrentDelegateAdapter.this.click.Click(datas.get(i));
            }
        });
        return view;
    }

    public class ViewHolder {
        private TextView tv_sign;
        private TextView tv_Currency_transaction;
        private TextView tv_number_Completed;
        private TextView tv_number_all;
        private TextView tv_price;
        private TextView tv_total;
        private Button bt_Delegate_status;
        private TextView tv_data;

    }

    public interface OnClick {
        void Click(MainBean.DataBean.ListBean dataBean);
    }

    public void getClickPst(OnClick click) {
        this.click = click;
    }
}
